package cn.wolfcode.trip.base.service.impl;


import cn.wolfcode.trip.base.domain.Room;
import cn.wolfcode.trip.base.mapper.RoomMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IRoomService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoomServiceImpl implements IRoomService{
    @Autowired
    private RoomMapper roomMapper;

    @Override
    public void saveOrUpdate(Room room) {

        if(room.getId() == null){
            roomMapper.insert(room);
        }else {
            roomMapper.updateByPrimaryKey(room);
        }
    }

    @Override
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Room> rooms = roomMapper.queryForList(qo);
        return new PageInfo(rooms);
    }

    @Override
    public List<Room> listRoomByHotleId(Long hotelId) {
        List<Room> rooms= roomMapper.listRoomByHotleId(hotelId);
        return rooms;
    }

    @Override
    public Room queryRoomById(Long id) {
        Room room=roomMapper.selectByPrimaryKey(id);
        return room;
    }

    @Override
    public void changeSumById(Long id) {
      roomMapper.changeSumById(id);
    }

    @Override
    public Room queryCurrentSum(Long id) {
        Room room=roomMapper.queryCurrentSum(id);
        return room;
    }


}
